// include dependencies
var express = require('express');
var proxy = require('http-proxy-middleware');

// proxy middleware options
var options = {
    target: 'http://127.0.0.1:3003', // target host
    changeOrigin: true, // needed for virtual hosted sites
    ws: true, // proxy websockets
    // pathRewrite: {
    //     '^/api/old-path': '/api/new-path', // rewrite path
    //     '^/api/remove/path': '/path' // remove base path
    // },
    router: function(req) {

        if (req.url.includes('biz=s1')) {
            return 'http://127.0.0.1:3003';
        } else {
            return 'http://127.0.0.1:3004';
        }
    }
};

// create the proxy (without context)
var exampleProxy = proxy(options);

// mount `exampleProxy` in web server
var app = express();

// app.use('/api', exampleProxy);

app.use(exampleProxy)

app.listen(3000, function () {
    console.log('listening on *:3000');
});